package com.zc.manager.notify.domain;

import com.alibaba.fastjson.JSON;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import com.zc.component.notify.core.NotifierProperties;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.HashMap;
import java.util.Map;

/**
 * 通知配置对象 notify_config
 *
 * @author wangjibao
 * @date 2022-11-10
 */
@Getter
@Setter
@ToString
public class NotifyConfig extends BaseEntity {


    /** 主键 */
    private Long id;

    /** 其他配置 */
//    @NotBlank(message = "其他配置不能为空")
    @Excel(name = "其他配置")
    @Size(max = 1000, message = "其他配置长度不能超过1000个字符")
    private String configuration;

    /** 服务商 */
    @Excel(name = "服务商")
    @NotBlank(message = "服务商不能为空")
    @Size(max = 30, message = "服务商长度不能超过30个字符")
    private String provider;

    /** 配置名称 */
    @Excel(name = "配置名称")
    @NotBlank(message = "配置名称不能为空")
    @Size(max = 30, message = "配置名称长度不能超过30个字符")
    private String name;


    /** 描述 */
    @Excel(name = "通知配置描述")
    @Size(max = 200, message = "描述不能超过200个字符")
    private String description;

    /** 类型 */
    @Excel(name = "通知类型")
    private String type;

    public NotifierProperties toProperties() {
        String con = configuration;
        Map<String, Object> map =(Map<String, Object>) JSON.parse(configuration);
        NotifierProperties properties = new NotifierProperties();
        properties.setProvider(provider);
        properties.setId( getId().toString());
        properties.setType(type);
        properties.setConfiguration(configuration == null ? new HashMap<>() : map);
        properties.setName(name);
        return properties;
    }

}
